package pers.ree.demo.concurrent;

public class InterruptDemo {

    public static void main(String[] args) {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
//                int i = 0;
                while (true) {

                    if (Thread.currentThread().isInterrupted()) {
                        System.out.println(Thread.currentThread().getName() + " before interrupted, isInterrupted=" + Thread.currentThread().isInterrupted());
                        System.out.println(Thread.currentThread().getName() + " interrupted=" + Thread.interrupted());
                        System.out.println(Thread.currentThread().getName() + " behind interrupted, isInterrupted=" + Thread.currentThread().isInterrupted());
                        break;
                    } else {
                        System.out.println(Thread.currentThread().getName() + " " + "not yet interrupted");
                    }
                }
            }
        });

        t.start();

        t.interrupt();

//        while (true) {
//            if (t.isInterrupted()) {
//                System.out.println("main end1 " + t.getName() + " isInterrupted=" + t.isInterrupted());
////                break;
//            } else {
//                System.out.println("main end2 " + t.getName() + " isInterrupted=" + t.isInterrupted());
//                t.interrupt();
//            }
//        }
    }
}
